/**
 * @author wxh
 */
public class MultiThread {

    private int num = 0;

    private synchronized void printNum(String tag) {
        if ("a".equals(tag)) {
            num = 100;
            System.out.println("tag a set num over!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else if ("b".equals(tag)) {
            num = 200;
            System.out.println("tag b set num over!");
        }

        System.out.println("tag " + tag + " num = " + num);
    }

    public static void main(String[] agrs) {
        final MultiThread t1 = new MultiThread();
        final MultiThread t2 = new MultiThread();
        new Thread(new Runnable() {
            @Override
            public void run() {
                t1.printNum("a");
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                t1.printNum("b");
            }
        }).start();


    }

}
